/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: AllOptionOrdersActivity.java
 *   @Date: 1/11/19 4:29 PM
 *   @Author: chenjun
 *   @Description:
 *   @Copyright（C）: 2019 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.app.account.ui;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Pair;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;

import java.util.ArrayList;

import io.bhex.app.R;
import io.bhex.app.account.presenter.AllOptionOrderPresenter;
import io.bhex.app.base.BaseActivity;
import io.bhex.app.event.OrderFilterEvent;
import io.bhex.app.skin.view.SkinTabLayout;
import io.bhex.app.utils.CommonUtil;
import io.bhex.app.view.TopBar;

public class AllOptionOrdersActivity extends BaseActivity<AllOptionOrderPresenter, AllOptionOrderPresenter.AllOptionOrderUI> implements AllOptionOrderPresenter.AllOptionOrderUI, View.OnClickListener, ViewPager.OnPageChangeListener {
    private SkinTabLayout tabLayout;
    private ViewPager viewPager;
    private ArrayList<Pair<String, Fragment>> items;
    private EntrustAdapter entrustAdapter;
    private TopBar topBar;
    private View revokeAllOrders;
    private View filterLayout;
    private boolean isShowFilter = false;
    private EditText baseTokenEt;
    private EditText quoteTokenEt;
    private RadioGroup orderStatusRadio;
    private RadioGroup priceModeRadio;
    private OrderFilterEvent filterEventCurrent = new OrderFilterEvent();
    private OrderFilterEvent filterEventHistory = new OrderFilterEvent();
    //默认是当前委托单列表
    private boolean isOpenOrders=true;
    //当前筛选条件
    private OrderFilterEvent currentFilterEvent;

    @Override
    protected int getContentView() {
        return R.layout.activity_all_option_orders_layout;
    }

    @Override
    protected AllOptionOrderPresenter createPresenter() {
        return new AllOptionOrderPresenter();
    }

    @Override
    protected AllOptionOrderPresenter.AllOptionOrderUI getUI() {
        return this;
    }

    @Override
    protected void initView() {
        super.initView();
        topBar = viewFinder.find(R.id.topBar);
        topBar.setLeftImg(R.mipmap.btn_head_back);
        topBar.setLeftOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        tabLayout = viewFinder.find(R.id.tabLayout);
        viewPager = viewFinder.find(R.id.viewPager);
        initTabs();
    }

    private void initTabs() {
        items = new ArrayList<>();

        items.add(new Pair<String, Fragment>(getString(R.string.string_current_entrust), new CurrentOptionEntrustOrderFragment()));
        items.add(new Pair<String, Fragment>(getString(R.string.string_current_hold), new CurrentOptionHoldOrderFragment()));
        items.add(new Pair<String, Fragment>(getString(R.string.string_history_entrust), new OptionHistoryOrderFragment()));
        items.add(new Pair<String, Fragment>(getString(R.string.string_history_deal), new OptionHistoryDealRecordFragment()));
        items.add(new Pair<String, Fragment>(getString(R.string.string_history_delivery), new OptionHistoryDeliverRecordFragment()));

        entrustAdapter = new AllOptionOrdersActivity.EntrustAdapter(getSupportFragmentManager());
        viewPager.setAdapter(entrustAdapter);
        tabLayout.setupWithViewPager(viewPager);
//        tab.setTabTextColors(getResources().getColor(R.color.color_white),getResources().getColor(R.color.color_black));
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

        viewPager.addOnPageChangeListener(this);
        CommonUtil.setUpIndicatorWidthByReflex(tabLayout,15,15);
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onClick(View v) {

    }

    private class EntrustAdapter extends FragmentPagerAdapter {

        public EntrustAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return items.get(position).second;
        }

        @Override
        public int getCount() {
            return items.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return items.get(position).first;
        }

    }
}
